Some times you need to produce html tables from existing database tables in some
cases like CGI programming. This example illustrates how to produce an html table
from Paradox, Foxpro, dBase tables or any other dataset:
Method 1: using HTML tags:
- Drop a Table, an OpenDialog, and a Button.
- At Filter property of OpenDialog1 write:
Database tables *.db;*.dbf;
- Add ShellApi to uses clause
- At Botton1 OnClick event write:
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
F: TextFile;
begin
if OpenDialog1.Execute then
begin (*** Open Source table ***) Screen.Cursor:= crHourGlass;
Table1.TableName:= OpenDialog1.FileName;
Table1.Open;
(*** Create HTML file ***)
AssignFile(F,
'c:\My Documents\Test.html');
Rewrite(F);
- Drop DataSetTableProducer from Internet Page
- At DataSetTableProducer's DataSet select your table or query you want to display.
- Expand TableAttribute property of DataSetTableProducer, Set Border property to 1
- Set MaxRows to -1 to dipsplay all the records in your dataset.
- Drop a button and write this code in it's OnClick event:
var
List: TStringList;
begin
Table1.Open;
List:= TStringList.Create;
List.Text:= DataSetTableProducer1.Content;
List.SaveToFile('table.htm');
List.Free;
Table1.Close;
ShellExecute(handle, 'open', 'table.htm',
nil, nil, sw_Normal);
end;
- Add ShellApi to uses clause to use ShellExecute function.